/**
 * @desc 工单中心 列表界面和详情界面 公用
 * @:主要解决维护多个地方
 */
import { getCloseOrderInfo } from "api/taskCenterApi";
export default function (page) {
  return [
    {
      tooltip: {
        content: "根据流程进行治理、验收或审批等动作",
      },
      label: ({ row }) => {
        return row.appeal === "3" ? "处理中" : "处理";
      },
      disabled: ({ row }) => {
        return row.appeal === "1" ? true : false;
      },
      prop: "handler",
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return status !== "doing" || row.operateConfigType == "anquan";
      },
      click: ({ row }) => {
        if (row.type === "audit-api") {
          this.selfInspectionHandle(row);
        } else {
          this.handle(row);
        }
      },
    },
    {
      tooltip: {
        content: "若短期内无法修复完成，可根据实际情况申请延期（修复截止日期之后将会继续收到工单的跟催提醒）",
      },
      label: ({ row }) => {
        return row.delayFlag ? "更改延期" : "延期";
      },
      disabled: ({ row }) => {
        return ["1", "3"].includes(row.appeal) ? true : false;
      },
      prop: "delayDate",
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return status !== "doing" || row.operateConfigType == "anquan";
      },
      click: ({ row }) => {
        this.delayDateHandle(row);
      },
    },
    {
      tooltip: {
        content: "将工单归属自己（认领后仍可至“进行中”进行转交或申诉）",
      },
      label: "认领",
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return status !== "pending" || row.operateConfigType == "anquan";
      },
      disabled: ({ row }) => {
        return this.isDisOptBtn(row);
      },
      click: ({ row }) => {
        //列表界面 由于点击认领有三个按钮，就不能公用一个封装方法
        if (page !== "detail") {
          this.receiveHandle(row);
        } else {
          //详情界面 认领、驳回以及列表界面批量认领和批量驳回走这里
          this.receiveOrRejectHandle(row, true);
        }
      },
    },
    {
      tooltip: {
        content: "将工单打回至安全部（不清楚工单归属时使用）",
      },
      label: "驳回",
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return status !== "pending" || row.operateConfigType == "anquan";
      },
      disabled: ({ row }) => {
        return this.isDisOptBtn(row);
      },
      click: ({ row }) => {
        this.receiveOrRejectHandle(row);
      },
    },
    {
      tooltip: {
        content: "将工单转交至其他人",
      },
      label: "转交",
      disabled: ({ row }) => {
        return this.isDisOptBtn(row);
      },
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return !["pending", "doing"].includes(status) || row.operateConfigType == "anquan";
      },
      click: ({ row }) => {
        this.handleDeliver(row);
      },
    },

    {
      tooltip: {
        content: "工单属于误报或暂不治理等",
      },
      hide: ({ row }) => {
        let status = this.getParams?.()?.status || row.status;
        return (
          !["pending", "doing"].includes(status) ||
          row.operateConfigType == "anquan" ||
          ["audit-api"].includes(row.type)
        );
      },
      label: ({ row }) => {
        return row.appeal === "1" ? (page === "detail" ? "申诉详情" : "申诉中") : "申诉";
      },
      disabled: ({ row }) => {
        return row.appeal === "3" ? true : false;
      },
      click: ({ row }) => {
        this.handleCloseOrder(row);
      },
    },
    {
      tooltip: {
        content: "新页面打开审批链接地址",
      },
      hide: ({ row }) => {
        //只有工单中心详情界面并且是申诉中时展示
        if (page !== "detail") return true;
        if (row.appeal !== "1") return true;
        let status = this.getParams?.()?.status || row.status;
        return (
          !["pending", "doing"].includes(status) ||
          row.operateConfigType == "anquan" ||
          ["audit-api"].includes(row.type)
        );
      },
      label: ({ row }) => {
        return row.appeal === "1" && "审批详情";
      },
      disabled: ({ row }) => {
        return row.appeal === "3" ? true : false;
      },
      click: ({ row }) => {
        getCloseOrderInfo({ processId: row.processId }).then((res) => {
          const { bpmUrl } = res.data;
          window.open(bpmUrl);
        });
      },
    },
  ];
}
//我的审批工单 操作列
export const approvalOpt = function () {
  return [
    {
      tooltip: {
        content: "根据流程进行治理、验收或审批等动作",
      },
      label: "处理",
      prop: "handler",
      hide: ({ row }) => {
        //已完成隐藏
        return this.approveStatus === "1" ? true : false;
      },
      click: ({ row }) => {
        if (row.type === "audit-api") {
          this.selfInspectionHandle(row);
        } else {
          this.handle(row);
        }
      },
    },
    {
      tooltip: {
        content: "将工单转交至其他人",
      },
      label: "转交",
      disabled: ({ row }) => {
        return ["1"].includes(row.appeal) ? true : false;
      },
      hide: ({ row }) => {
        return this.approveStatus === "1" || row.operateConfigType == "anquan";
      },
      click: ({ row }) => {
        this.handleDeliver(row);
      },
    },
  ];
};
